<template>
    <has-left-nav-layout>
        <template v-slot:leftNav>
            <left-menu :lists="menus"/>
        </template>
        <router-view></router-view>
    </has-left-nav-layout>
</template>

<script>

import { reactive,toRefs,getCurrentInstance,onMounted,computed } from 'vue'
import {useRoute,useRouter} from 'vue-router'
import { useStore } from 'vuex'
import hasLeftNavLayout from '@/components/hasLeftNavLayout.vue'
import leftMenu from '@/components/leftMenu.vue'
import { useI18n } from 'vue-i18n'

export default {
    components:{
       hasLeftNavLayout,
       leftMenu
    },
    props:{

    },
    setup(props,context){
        const router = useRouter()
        const route = useRoute()
        const store = useStore()
        const {proxy} = getCurrentInstance()
        const {t} = useI18n()

        const state = reactive({
            userInfo:computed(()=>store.state.base.userInfo),
            menus:[
                {name:t('shop.text1'),num:0,path:'/shop/list'},
                {name:t('shop.text2'),num:0,path:'/shop/goods'},
                {name:t('shop.text3'),num:0,path:'/shop/coupons'}
            ],
            arLandmarkId:''
        })

        onMounted(()=>{
            state.arLandmarkId = route.query.cityid
            // 获取城市下的数据时，重新设置菜单
            if(state.arLandmarkId){
                state.menus=[
                    {name:t('prop.tab8'),key:'adNum', num:0,path:`/ad/space?cityid=${state.arLandmarkId}`},
                    {name:t('prop.tab9'),key:'propNum',num:0,path:`/prop?cityid=${state.arLandmarkId}`},
                    {name:t('prop.tab10'),key:'shopNum',num:0,path:`/shop/list?cityid=${state.arLandmarkId}`},
                    {name:t('prop.tab11'),key:'gameNum',num:0,path:`/game?cityid=${state.arLandmarkId}`},
                    {name:t('prop.tab12'),key:'VenuesNum',num:0,path:`/venues?cityid=${state.arLandmarkId}`}
                ]
                getCityTotal()  // 获取数量
            }else{
                store.dispatch("shop/get_shop_list", {
                    page: 1,
                    limit: 1,
                    keyWord:'',
                    orderField: '',
                    orderType: ''
                }).then(res =>{
                    state.menus[0].num = res.total
                })
                store.dispatch("shop/get_goods_list", {
                    keyWord: "",
                    limit: 1,
                    orderField: 1,
                    orderType: "desc",
                    page: 1,
                    shopId: "",
                }).then(res =>{
                    state.menus[1].num = res.total
                })
                store.dispatch("shop/get_coupon_list", {
                    keyWord: "",
                    limit: 1,
                    orderField: 1,
                    orderType: "desc",
                    page: 1,
                    shopId: "",
                    walletAddress:state.userInfo.walletAddress
                }).then(res =>{
                    state.menus[2].num = res.total
                })
            }
            
        })

        // 获取城市下的广告位、道具、店铺等数量
        const getCityTotal = ()=>{
            store.dispatch('base/get_arLandmarkek_detail',{
                arLandmarkId:state.arLandmarkId,
                 walletAddress:state.userInfo.walletAddress
            }).then(res =>{
                if(res.success){
                     state.menus.map((item)=>{
                         if(res.data[item.key]){
                              item.num=res.data[item.key]||'0'
                         }else{
                             item.num='0'
                         }
                         return item
                     })
                }
            })
        }

        return{
            ...toRefs(state)
        }
    }
}
</script>

<style lang="scss" scoped>
    
</style>